local _, GrifonOvaleScripts = ...

GrifonOvaleScripts.script.PALADIN.Attilio = {
	desc = "[5.4] Attilio: Retribution",
	code =
[[

Define(alabaster_shield 121467)
	SpellInfo(alabaster_shield duration=12)
Define(ancient_power 86700)
	SpellInfo(ancient_power duration=30)
Define(ardent_defender 31850)
	SpellInfo(ardent_defender cd=180 duration=10)
	SpellInfo(ardent_defender addcd=-60 itemset=T14_tank itemcount=2)
	SpellAddBuff(ardent_defender ardent_defender=1)
Define(avengers_shield 31935)
	SpellInfo(avengers_shield buff_holy=grand_crusader cd=15 duration=3)
	SpellInfo(avengers_shield cd_haste=melee haste=melee if_spell=sanctity_of_battle)
	SpellAddBuff(avengers_shield grand_crusader=0)
	SpellAddTargetDebuff(avengers_shield avengers_shield=1)
Define(avenging_wrath 31884)
	SpellInfo(avenging_wrath cd=180 duration=20)
	SpellInfo(avenging_wrath addduration=10 talent=sanctified_wrath_talent)
	SpellInfo(avenging_wrath addcd=-65 itemset=T14_melee itemcount=4)
	SpellAddBuff(avenging_wrath avenging_wrath=1)
Define(bastion_of_glory 114637)
	SpellInfo(bastion_of_glory duration=20)
Define(beacon_of_light 53563)
	SpellInfo(beacon_of_light cd=3)
Define(blessing_of_kings 20217)
	SpellInfo(blessing_of_kings duration=3600)
	SpellAddBuff(blessing_of_kings blessing_of_kings=1)
Define(blessing_of_might 19740)
	SpellInfo(blessing_of_might duration=3600)
	SpellAddBuff(blessing_of_might blessing_of_might=1)
Define(blinding_light 115750)
	SpellInfo(blinding_light cd=120)
Define(burden_of_guilt 110300)
	SpellInfo(burden_of_guilt duration=12)
Define(burden_of_guilt_talent 6)
Define(censure 31803)
	SpellInfo(censure duration=15)
Define(cleanse 4987)
	SpellInfo(cleanse cd=8)
Define(consecration 26573)
	SpellInfo(consecration cd=9 duration=9 tick=1)
	SpellInfo(consecration cd_haste=melee haste=melee if_spell=sanctity_of_battle)
Define(consecration_glyphed 116467)
Define(crusader_strike 35395)
	SpellInfo(crusader_strike holy=-1 cd=4.5)
	SpellInfo(crusader_strike cd_haste=melee haste=melee if_spell=sanctity_of_battle)
Define(daybreak 88819)
	SpellInfo(daybreak duration=10)
Define(denounce 2812)
	SpellInfo(denounce duration=4)
	SpellAddBuff(denounce glyph_of_denounce_aura=0)
	SpellAddTargetDebuff(denounce denounce=1)
Define(devotion_aura 31821)
	SpellInfo(devotion_aura cd=180 duration=6)
	SpellAddBuff(devotion_aura devotion_aura=1)
Define(divine_favor 31842)
	SpellInfo(divine_favor cd=180 duration=20)
	SpellAddBuff(divine_favor divine_favor=1)
Define(divine_light 82326)
	SpellAddBuff(divine_light infusion_of_light=0)
Define(divine_plea 54428)
	SpellInfo(divine_plea cd=120 duration=9)
	SpellAddBuff(divine_plea divine_plea=1)
Define(divine_protection 498)
	SpellInfo(divine_protection cd=60 duration=10)
Define(divine_purpose 90174)
	SpellInfo(divine_purpose duration=8)
Define(divine_purpose_talent 15)
Define(divine_shield 642)
	SpellInfo(divine_shield cd=300 duration=8)
	SpellAddBuff(divine_shield divine_shield=1)
	SpellAddDebuff(divine_shield forbearance=1)
Define(divine_storm 53385)
	SpellInfo(divine_storm holy=3)
	SpellAddBuff(divine_storm divine_purpose=0)
Define(emancipate 121783)
Define(eternal_flame 114163)
	SpellInfo(eternal_flame duration=30 haste=spell holy=1 tick=3)
	SpellAddBuff(eternal_flame bastion_of_glory=0 divine_purpose=0)
Define(eternal_flame_talent 8)
Define(execution_sentence 114157)
	SpellInfo(execution_sentence cd=60)
	SpellAddTargetDebuff(execution_sentence execution_sentence_aura=1)
Define(execution_sentence_aura 114916)
	SpellInfo(execution_sentence_aura duration=10 haste=spell tick=1)
Define(execution_sentence_talent 18)
Define(exorcism 879)
	SpellInfo(exorcism holy=-1 cd=15)
	SpellInfo(exorcism cd_haste=melee haste=melee if_spell=sanctity_of_battle specialization=3)
Define(exorcism_glyphed 122032)
	SpellInfo(exorcism_glyphed holy=-1 cd=15)
	SpellInfo(exorcism_glyphed cd_haste=melee haste=melee if_spell=sanctity_of_battle specialization=3)
Define(exorcism_aura 138162)
	SpellInfo(exorcism_aura duration=6)
Define(fist_of_justice 105593)
	SpellInfo(fist_of_justice cd=30 duration=6)
	SpellAddTargetDebuff(fist_of_justice fist_of_justice=1)
Define(fist_of_justice_talent 4)
Define(flash_of_light 19750)
	SpellAddBuff(flash_of_light selfless_healer=0 supplication=0)
Define(forbearance 25771)
	SpellInfo(forbearance duration=60)
Define(glyph_of_avenging_wrath_aura 115547)
	SpellInfo(glyph_of_avenging_wrath_aura duration=20 tick=2)
	SpellInfo(glyph_of_avenging_wrath_aura addduration=10 talent=sanctified_wrath_talent)
Define(glyph_of_consecration 54928)
Define(glyph_of_denounce_aura 115654)
Define(glyph_of_divine_plea 63223)
Define(glyph_of_divinity 54939)
Define(glyph_of_double_jeopardy_aura 121027)
	SpellInfo(glyph_of_double_jeopardy_aura duration=10)
Define(glyph_of_flash_of_light_aura 54957)
	SpellInfo(glyph_of_flash_of_light_aura duration=7)
Define(glyph_of_focused_shield 54930)
Define(glyph_of_harsh_words 54938)
Define(glyph_of_mass_exorcism 122028)
Define(glyph_of_rebuke 54925)
Define(glyph_of_templars_verdict_aura 115668)
	SpellInfo(glyph_of_templars_verdict_aura duration=6)
Define(glyph_of_turn_evil 54931)
Define(glyph_of_word_of_glory 54936)
Define(glyph_of_word_of_glory_aura 115522)
	SpellInfo(glyph_of_word_of_glory_aura duration=6)
Define(grand_crusader 85416)
	SpellInfo(grand_crusader duration=6)
Define(guardian_of_ancient_kings_holy 86669)
	SpellInfo(guardian_of_ancient_kings_holy cd=300 duration=30)
	SpellAddBuff(guardian_of_ancient_kings_holy guardian_of_ancient_kings_holy=1)
Define(guardian_of_ancient_kings_protection 86659)
	SpellInfo(guardian_of_ancient_kings_protection cd=180 duration=12)
	SpellAddBuff(guardian_of_ancient_kings_protection guardian_of_ancient_kings_protection=1)
Define(guardian_of_ancient_kings_retribution 86698)
	SpellInfo(guardian_of_ancient_kings_retribution cd=300 duration=30)
	SpellAddBuff(guardian_of_ancient_kings_retribution guardian_of_ancient_kings_retribution=1)
Define(hammer_of_justice 853)
	SpellInfo(hammer_of_justice cd=60 duration=6)
	SpellAddTargetDebuff(hammer_of_justice hammer_of_justice=1)
Define(hammer_of_the_righteous 53595)
	SpellInfo(hammer_of_the_righteous holy=-1 cd=4.5)
	SpellInfo(hammer_of_the_righteous cd_haste=melee haste=melee if_spell=sanctity_of_battle)
	SpellAddTargetDebuff(hammer_of_the_righteous weakened_blows=1)
Define(hammer_of_wrath 24275)
	SpellInfo(hammer_of_wrath cd=6)
	SpellInfo(hammer_of_wrath cd_haste=melee haste=melee if_spell=sanctity_of_battle)
	SpellInfo(hammer_of_wrath holy=-1 specialization=3)
Define(hand_of_freedom 1044)
	SpellInfo(hand_of_freedom cd=25 duration=6)
Define(hand_of_protection 1022)
	SpellInfo(hand_of_protection cd=300 duration=10)
	SpellAddTargetDebuff(hand_of_protection forbearance=1)
Define(hand_of_purity 114039)
	SpellInfo(hand_of_purity cd=30 duration=6)
Define(hand_of_purity_talent 10)
Define(hand_of_sacrifice 6940)
	SpellInfo(hand_of_sacrifice cd=120 duration=12)
Define(hand_of_salvation 1038)
	SpellInfo(hand_of_salvation cd=120 duration=10)
Define(harsh_word 130552)
	SpellInfo(harsh_word holy=1)
	SpellAddBuff(harsh_word divine_purpose=0)
Define(holy_avenger 105809)
	SpellInfo(holy_avenger cd=120 duration=18)
Define(holy_avenger_talent 13)
Define(holy_light 635)
	SpellAddBuff(holy_light infusion_of_light=0)
Define(holy_prism 114165)
	SpellInfo(holy_prism cd=20)
Define(holy_prism_talent 16)
Define(holy_radiance 82327)
	SpellAddBuff(holy_radiance daybreak=1 infusion_of_light=0)
Define(holy_shock 20473)
	SpellInfo(holy_shock cd=6 holy=-1)
	SpellInfo(holy_shock cd=5 itemset=T14_heal itemcount=4)
	SpellAddBuff(holy_shock daybreak=0)
Define(holy_wrath 119072)
	SpellInfo(holy_wrath cd=9 duration=3)
	SpellInfo(holy_wrath cd_haste=melee haste=melee if_spell=sanctity_of_battle)
Define(infusion_of_light 54149)
	SpellInfo(infusion_of_light duration=15)
Define(judgment 20271)
	SpellInfo(judgment cd=6)
	SpellInfo(judgment cd_haste=melee haste=melee if_spell=sanctity_of_battle)
	SpellInfo(judgment holy=-1 if_spell=judgments_of_the_bold)
	SpellInfo(judgment holy=-1 if_spell=judgments_of_the_wise)
Define(judgments_of_the_bold 111529)
Define(judgments_of_the_pure_aura 53657)
	SpellInfo(judgments_of_the_pure_aura duration=60)
Define(judgments_of_the_wise 105424)
Define(lay_on_hands 633)
	SpellInfo(lay_on_hands cd=600)
	SpellInfo(lay_on_hands addcd=720 glyph=glyph_of_divinity)
	SpellAddTargetDebuff(lay_on_hands forbearance=1)
Define(light_of_ancient_kings 86678)
	SpellInfo(light_of_ancient_kings duration=8)
Define(light_of_dawn 85222)
	SpellInfo(light_of_dawn holy=1)
	SpellAddBuff(light_of_dawn divine_purpose=0)
Define(lights_hammer 114158)
	SpellInfo(lights_hammer cd=60)
Define(lights_hammer_talent 17)
Define(rebuke 96231)
	SpellInfo(rebuke cd=15)
	SpellInfo(rebuke addcd=5 glyph=glyph_of_rebuke)
Define(reckoning 62124)
	SpellInfo(reckoning cd=8 duration=3)
	SpellAddTargetDebuff(reckoning reckoning=3)
Define(redemption 7328)
Define(repentance 20066)
	SpellInfo(repentance cd=15 duration=60)
	SpellAddTargetDebuff(repentance repentance=1)
Define(repentance_talent 5)
Define(righteous_fury 25780)
Define(sacred_shield 20925)
	SpellInfo(sacred_shield cd=6 duration=30 haste=spell tick=6)
	SpellAddBuff(sacred_shield sacred_shield=1)
Define(sacred_shield_aura 65148)
	SpellInfo(sacred_shield_aura duration=6)
Define(sacred_shield_talent 9)
Define(sanctified_wrath 114232)
	SpellInfo(sanctified_wrath duration=30)
Define(sanctified_wrath_talent 14)
Define(sanctity_of_battle 25956)
Define(seal_of_command 105361)
Define(seal_of_insight 20165)
Define(seal_of_justice 20164)
Define(seal_of_justice_aura 20170)
	SpellInfo(seal_of_justice_aura duration=8)
Define(seal_of_righteousness 20154)
Define(seal_of_truth 31801)
Define(selfless_healer 114250)
	SpellInfo(selfless_healer duration=15)
Define(selfless_healer_talent 7)
Define(shield_of_the_righteous 53600)
	SpellInfo(shield_of_the_righteous cd=1.5 holy=3)
	SpellInfo(shield_of_the_righteous cd_haste=melee haste=melee if_spell=sanctity_of_battle)
	SpellAddBuff(shield_of_the_righteous alabaster_shield=0 bastion_of_glory=1 divine_purpose=0 shield_of_the_righteous_buff=1)
Define(shield_of_the_righteous_divine_purpose 132403)
	SpellInfo(shield_of_the_righteous_divine_purpose cd_haste=melee haste=melee if_spell=sanctity_of_battle)
	SpellAddBuff(shield_of_the_righteous_divine_purpose alabaster_shield=0 bastion_of_glory=1 divine_purpose=0 shield_of_the_righteous_buff=1)
Define(shield_of_the_righteous_buff 132403)
	SpellInfo(shield_of_the_righteous_buff duration=3)
Define(speed_of_light 85499)
	SpellInfo(speed_of_light cd=45 duration=8)
Define(speed_of_light_talent 1)
Define(stay_of_execution 114917)
	SpellInfo(stay_of_execution duration=10 haste=spell tick=1)
Define(supplication 94686)
	SpellInfo(supplication duration=8)
Define(templars_verdict 85256)
	SpellInfo(templars_verdict holy=3)
	SpellAddBuff(templars_verdict divine_purpose=0)
Define(turn_evil 10326)
	SpellInfo(turn_evil duration=40)
	SpellInfo(turn_evil cd=8 glyph=glyph_of_turn_evil)
	SpellAddTargetDebuff(turn_evil turn_evil=1)
Define(weakened_blows 115798)
	SpellInfo(weakened_blows duration=30)
Define(word_of_glory 85673)
	SpellInfo(word_of_glory holy=1)
	SpellAddBuff(word_of_glory bastion_of_glory=0 divine_purpose=0)
Define(word_of_glory_divine_purpose 130551)
	SpellAddBuff(word_of_glory_divine_purpose bastion_of_glory=0 divine_purpose=0)
Define(word_of_glory_glyphed 136494)
	SpellInfo(word_of_glory_glyphed holy=1)
	SpellAddBuff(word_of_glory_glyphed bastion_of_glory=0 divine_purpose=0)

# Items
ItemList(darkmist_vortex 86894 86336 87172)
Define(darkmist_vortex_buff 126657)
ItemList(lei_shens_final_orders 86802 86144 87072)
Define(lei_shens_final_orders_buff 126582)
Define(mogu_power_potion 76095)
Define(mogu_power_potion_buff 105706)
	SpellInfo(mogu_power_potion_buff duration=25)

# Racials
Define(arcane_torrent_chi 129597)
	SpellInfo(arcane_torrent_chi cd=120 chi=1)
Define(berserking 26297)
	SpellInfo(berserking cd=180 duration=10)
	SpellAddBuff(berserking berserking=1)
Define(blood_fury 20572)
	SpellInfo(blood_fury cd=120 duration=15)
	SpellAddBuff(blood_fury blood_fury=1)
Define(quaking_palm 107079)
	SpellInfo(quaking_palm cd=120 duration=4)
	SpellAddTargetDebuff(quaking_palm quaking_palm=1)
Define(stoneform 20594)
	SpellInfo(stoneform cd=120 duration=8)
	SpellAddBuff(stoneform stoneform=1)

AddFunction UseRacialActions
{
	Spell(berserking)
	Spell(blood_fury)
}

AddFunction UseRacialInterruptActions
{
	Spell(arcane_torrent_chi)
	if target.InRange(quaking_palm) Spell(quaking_palm)
}

AddFunction UseRacialSurvivalActions
{
	Spell(stoneform)
}

AddCheckBox(potions "Use potions" default)

AddCheckBox(ancient_king_auto "use auto ancient king" default)
AddCheckBox(avenging_wrath_auto "use auto avenging wrath" default)
AddCheckBox(autoheal "use auto heal" default)
AddCheckBox(AutoInterrupt "AutoInterrupt" default)
AddCheckBox(autoAOE "use auto AOE mode" default)
AddCheckBox(autoLayOnHand "use auto Lay On Hand" default)




AddFunction UseItemActions
{
	Item(HandsSlot usable=1)
}

###
### Paladin (all specializations)
###

AddFunction HasMaxHolyPower
{
	BuffPresent(divine_purpose) or HolyPower() ==5 or {Level() <85 and HolyPower() >=3}
}

AddFunction HasThreeHolyPower
{
	BuffPresent(divine_purpose) or HolyPower() >=3
}

AddFunction Interrupt
{
	if CheckBoxOn(AutoInterrupt) and {target.IsFriend(no) or {target.IsFriend() and target.IsCharmed()} } and target.IsInterruptible()
	{
		if target.InRange(rebuke) Spell(rebuke)
		if TalentPoints(fist_of_justice_talent) and target.Distance(less 20) Spell(fist_of_justice)
		if not TalentPoints(fist_of_justice_talent) and target.InRange(hammer_of_justice) Spell(hammer_of_justice)
		if target.InRange(rebuke) Spell(blinding_light)
		UseRacialInterruptActions()
	}
}


AddFunction Heal
{
	if CheckBoxOn(autoLayOnHand) and player.HealthPercent() <= 15 Spell(lay_on_hands)
	if TalentPoints(selfless_healer_talent) and player.HealthPercent() <= 70 and BuffStacks(selfless_healer) >=3 Spell(flash_of_light)
        if BuffPresent(divine_purpose) and player.HealthPercent() <= 40 Spell(word_of_glory_divine_purpose)
	if BuffExpires(divine_purpose) and player.HealthPercent() <= 40 and HolyPower() >=3 Spell(word_of_glory)
        if TalentPoints(selfless_healer_talent) and player.HealthPercent() <= 40 and BuffStacks(selfless_healer) >= 2 Spell(flash_of_light)
        if TalentPoints(selfless_healer_talent) and player.HealthPercent() <= 30 and BuffStacks(selfless_healer) >= 1 Spell(flash_of_light)
}


###
### Retribution
###

AddFunction RetributionUsePotion
{
	#mogu_power_potion
	if CheckBoxOn(potions) and target.Classification(worldboss) Item(mogu_power_potion usable=1)
}

AddFunction RetributionFullRotation
{
	
	if BuffExpires(str_agi_int 400 any=1) Spell(blessing_of_kings)
	if BuffExpires(mastery 400 any=1) and BuffExpires(str_agi_int 400 any=1) Spell(blessing_of_might)
	if CheckBoxOn(autoAOE) and Enemies() >=4 and CheckBoxOn(autoAOE) and not Stance(paladin_seal_of_righteousness) Spell(seal_of_righteousness)
	if CheckBoxOn(autoAOE) and Enemies() < 4 and not Stance(paladin_seal_of_truth) Spell(seal_of_truth)

        if CheckBoxOn(autoAOE) 
   	{
        	if Enemies() >=4 and not Stance(paladin_seal_of_righteousness) Spell(seal_of_righteousness)
		if Enemies() < 4 and not Stance(paladin_seal_of_truth) Spell(seal_of_truth)
	}
        if CheckBoxOn(autoheal) Heal()

        if IsRooted()
	{
		Spell(hand_of_freedom)
		Spell(emancipate)
	}

	Interrupt()
	if BuffPresent(burst_haste any=1) or {BuffPresent(ancient_power) and BuffPresent(avenging_wrath)} or target.TimeToDie() <=40 RetributionUsePotion()
	
	if CheckBoxOn(avenging_wrath_auto)
	{
		Spell(avenging_wrath)
	}
		
	UseRacialActions()
	if target.TimeToDie() > 10
	{
		if TalentPoints(execution_sentence_talent) and target.InRange(execution_sentence) Spell(execution_sentence)
	}
	if HasMaxHolyPower() or BuffPresent(divine_purpose) or {BuffPresent(holy_avenger) and HolyPower() >=3}
	{
		if CheckBoxOn(autoAOE) and Enemies() >=2 Spell(divine_storm)
		if target.InRange(templars_verdict) Spell(templars_verdict)
	}
	if BuffPresent(144595) Spell(divine_storm)
	if SpellKnown(hammer_of_wrath) and {BuffPresent(avenging_wrath) or target.HealthPercent() < 20}
	{
		if target.InRange(hammer_of_wrath) Spell(hammer_of_wrath)
		if target.InRange(hammer_of_wrath) and SpellCooldown(hammer_of_wrath) >0 and SpellCooldown(hammer_of_wrath) <= 0.2
			wait Spell(hammer_of_wrath) 
	}
	if CheckBoxOn(autoAOE) and Enemies() >= 2 and target.InRange(hammer_of_the_righteous) 
	{
		Spell(hammer_of_the_righteous)
		if SpellCooldown(hammer_of_the_righteous) >0 and SpellCooldown(hammer_of_the_righteous) <=0.2
			wait Spell(hammer_of_the_righteous)
	}
	if SpellKnown(crusader_strike) and target.InRange(crusader_strike)
	{
		Spell(crusader_strike)
		if SpellCooldown(crusader_strike) >0 and SpellCooldown(crusader_strike) <=0.2
			wait Spell(crusader_strike)
	}
	if target.InRange(judgment) Spell(judgment)
        if not Glyph(glyph_of_mass_exorcism) and SpellKnown(exorcism)
	{
		if target.InRange(exorcism) Spell(exorcism)
		if target.InRange(exorcism) and SpellCooldown(exorcism) >0 and SpellCooldown(exorcism) <= 0.2
			wait Spell(exorcism)
	}
        if Glyph(glyph_of_mass_exorcism) and SpellKnown(exorcism_glyphed)
	{
		if target.InRange(exorcism_glyphed) Spell(exorcism_glyphed)
		if target.InRange(exorcism_glyphed) and SpellCooldown(exorcism_glyphed) >0 and SpellCooldown(exorcism_glyphed) <= 0.2
			wait Spell(exorcism_glyphed)
	}
	if HolyPower() >= 3
	{
		if CheckBoxOn(autoAOE) and Enemies() >= 2 Spell(divine_storm)
		if target.InRange(templars_verdict) Spell(templars_verdict)
	}
	if TalentPoints(holy_prism_talent) and target.InRange(holy_prism)
	{
		Spell(holy_prism)
	}
}



### Retribution Icons

AddIcon specialization=3 help=main
{
	RetributionFullRotation()
}



]],
}
